package org.example.controller;

import lombok.AllArgsConstructor;
import org.example.dao.Comment;
import org.example.dao.Result;
import org.example.enums.responseEnum;
import org.example.service.CommentService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@AllArgsConstructor
@RestController
@RequestMapping("/comment")
public class CommentController {
    private final CommentService commentService;

    //添加评论
    @PostMapping("/addComment")
    public Result addComment(@RequestBody Comment comment) {
        responseEnum res = commentService.addComment(comment);
        if (res == responseEnum.success) {
            return new Result(200, "添加成功", null);
        } else if (res == responseEnum.error) {
            return new Result(500, "添加失败", null);
        } else {
            return new Result(400, "评论数量已达上限", null);
        }
    }

    //获取评论
    @PostMapping("/getComment")
    public Result getSongComment(@RequestBody Comment comment) {
        List<Comment> songComment = commentService.getComment(comment);
        if (songComment != null) {
            return new Result(200, "获取成功", songComment);
        } else {
            return new Result(404, "404 NotFind", null);
        }
    }

    @PostMapping("/deleteComment")
    public Result deleteComment(Comment comment) {
        responseEnum res = commentService.deleteComment(comment);
        if (res == responseEnum.success) {
            return new Result(200, "删除成功", null);
        } else {
            return new Result(500, "删除失败", null);
        }
    }
}

